//
// Created by mabinjie on 2024/10/30.
//

#ifndef PARTIAL_BODY_HPP
#define PARTIAL_BODY_HPP
#include "jtt808_body.hpp"
#include "common/serializer/reader.hpp"
#include "common/serializer/writer.hpp"

namespace protocol {

class PartialBody final : public jtt808_body {
public:
    common::Serialized serialized_;
    explicit PartialBody(const size_t size) : serialized_(size){ }
    explicit PartialBody(const common::Serialized &serialized, const uint16_t message_id = 0xffff) : jtt808_body(message_id), serialized_(serialized) {}

protected:
    [[nodiscard]] size_t size() const override {
        return serialized_.size;
    }

public:
    [[nodiscard]] std::string toString() const override {
        return "Partial Body";
    }

    void serialize(common::MessagePackWriter &writer) override {
        writer.writePointer(reinterpret_cast<uint8_t*>(serialized_.data), serialized_.size);
    }

    void deserialize(common::MessagePackReader &reader) override {
        reader.readPointer(serialized_.data, serialized_.size);
    }
};

}

#endif //PARTIAL_BODY_HPP
